﻿using Infragistics.Documents.Excel;
using VNet.VisiSuite.ExcelReader.ExcelReader;
using VNet.VisiSuite.ExcelReader.ExcelReaderFactory;

namespace VNet.VisiSuite.ExcelReader
{
    /// <summary>
    /// ExcelReaders
    /// </summary>
    public class ExcelReaders
    {
        /// <summary>
        /// The _workbook
        /// </summary>
        private static Workbook _workbook;

        /// <summary>
        /// Imports the product.
        /// </summary>
        /// <param name="fileLocation">The file location.</param>
        public IExcelData GetProducts(string fileLocation)
        {
            InitData(fileLocation);
            if (_workbook != null)
            {
                var reader = new ExcelReader<ProductReader>();
                return reader.Read(_workbook);
            }
            return null;
        }

        /// <summary>
        /// Gets the production plans.
        /// </summary>
        /// <param name="fileLocation">The file location.</param>
        /// <returns></returns>
        public IExcelData GetProductionPlans(string fileLocation)
        {
            InitData(fileLocation);
            if (_workbook != null)
            {
                var reader = new ExcelReader<ProductionPlanReader>();
                return reader.Read(_workbook);
            }
            return null;
        }

        /// <summary>
        /// Initializes the data.
        /// </summary>
        /// <param name="fileLocation">The file location.</param>
        private static void InitData(string fileLocation)
        {
            // Load the excel
            _workbook = Workbook.Load(fileLocation);
        }
    }
}
